(function() {
	tinymce.create('tinymce.plugins.FileMgrPlugin', {
		init: function(ed, url) {
			// Register commands
			ed.addCommand('mceFileMgr', function() {
				var path = '/Admin/Media?allowMceInsert=true'; //temporary solution
				if (window["mceTaskFolderId"] != null && !isNaN(mceTaskFolderId)) {
					path = path + '&folderId=' + mceTaskFolderId.toString();
				}
				ed.windowManager.open({
					file: path,
					width: 640 + parseInt(ed.getLang('FileMgr.delta_width', 0)),
					height: 400 + parseInt(ed.getLang('FileMgr.delta_height', 0)),
					inline: 1
				}, {
					plugin_url: url
				});
			});

			// Register buttons
			ed.addButton('FileMgr',
							{
								title: 'FileMgr.FileMgr_desc',
								cmd: 'mceFileMgr',
								image: url + '/img/filemgr.gif'
							}
						);
		},

		getInfo: function() {
			return {
				longname: 'File Manager',
				author: 'Mindfor, Ltd.',
				authorurl: 'http://mindfor.ru',
				infourl: 'http://mindfor.ru',
				version: tinymce.majorVersion + "." + tinymce.minorVersion
			};
		}
	});

	// Register plugin
	tinymce.PluginManager.add('FileMgr', tinymce.plugins.FileMgrPlugin);
})();